﻿using UnityEngine;

namespace UnityX
{
    [DisallowMultipleComponent]
    [AddComponentMenu("Animation/Scale In")]
    public class ScaleIn : AnimationBehaviour
    {
        public Vector3 scale = Vector3.zero;
        public AnimationValueType valueType = AnimationValueType.固定值;

        private Vector3 m_BeginValue;
        private Vector3 m_EndValue;

        protected override void Begin()
        {
            switch (valueType)
            {
                case AnimationValueType.固定值:
                    m_BeginValue = scale;
                    break;
                case AnimationValueType.固定增加:
                    m_BeginValue = transform.localScale + scale;
                    break;
                case AnimationValueType.倍数:
                    m_BeginValue = transform.localScale;
                    m_BeginValue = new Vector3(m_BeginValue.x * scale.x, m_BeginValue.y * scale.y, m_BeginValue.z * scale.z);
                    break;
            }
            m_EndValue = transform.localScale;
            transform.localScale = m_BeginValue;
        }
        protected override void End()
        {
            transform.localScale = m_EndValue;
        }
        protected override void Set(float t)
        {
            transform.localScale = Vector3.Lerp(m_BeginValue, m_EndValue, t);
        }
    }
}